#include "pointMotion.h"


//
// point to point collision
//
short caseMove;	  //for two-point collision
short case3Move;  //for three point collision
int colisionPointFlag=0;
long P3Flag = 0;



int maxSpeed (void)
{
	short max;
	if (points[0].speed >= points[1].speed)
		max = points[0].speed;
	else 
		max = points[1].speed ;

	if (max < points[2].speed)
		max =  points[2].speed;

	return max;
	

}

int point2pointColisionFreeCell(void)						// point to point collision 
{															// when they are symmetric	
															// and the are in conflict for free cell	
   if (pointsNext[2]==1 && pointsNext[5]==0)
   caseMove = 1;
   if (pointsNext[2]==0 && pointsNext[5]==1)
   caseMove = 2;
    if (pointsNext[2]==1 && pointsNext[5]==1)
  	caseMove= 3;
   if (pointsNext[2]==1 && pointsNext[8]==1)
  	caseMove= 4;
   if (pointsNext[2]==1 && pointsNext[8]==0)
   caseMove = 5;
   if (pointsNext[2]==0 && pointsNext[8]==1)
   caseMove = 6;
   if (pointsNext[5]==1 && pointsNext[8]==0)
   caseMove = 7;
   if (pointsNext[5]==0 && pointsNext[8]==1)
   caseMove = 8;
   if (pointsNext[5]==1 && pointsNext[8]==1)
  	caseMove= 9;
  



	if(pointsNext[0] == pointsNext[3] && pointsNext[1]==pointsNext[4] )		 // point1 to point2 collision
																			 //
	{  
	switch (caseMove)
		{
		case 1:
		colisionPointFlag ^= caseMove;
		break;
		case 2:
		colisionPointFlag ^= caseMove;
		break;
		case 3:
		colisionPointFlag ^= caseMove;
		break;
		default:
		break;
		}
								 
	}


	if(pointsNext[0] == pointsNext[6] && pointsNext[1]==pointsNext[7] )		 // point1 to point3 collision
																			 //
	{
	switch (caseMove)
		{
		case 4:
		colisionPointFlag ^= 0x04;
		break;
		case 5:
		colisionPointFlag ^= 0x08;
		break;
		case 6:
		colisionPointFlag ^= 0x0C;
		break;
		default:
		break;
		}
								 
	}
  

	if(pointsNext[3] == pointsNext[6] && pointsNext[4]==pointsNext[7] )		 // point2 to point3 collision
																			 //
	{
		switch (caseMove)
		{
		case 7:
		colisionPointFlag ^= 0x10;
		break;
		case 8:
		colisionPointFlag ^= 0x20;
		break;
		case 9:
		colisionPointFlag ^= 0x30;
		break;
		default:
		break;
		}
								 
	}

	 if (colisionPointFlag >0 && colisionPointFlag <=48 )
	return colisionPointFlag;
	else
	return 0;
}




int PPCollisionAsymetric (void)
{


 	 if( abs(points[0].x - points[1].x)== 1)
	 {
	 	if (abs (pointsNext[0] - pointsNext[3]) == 1 )
		{
			if (points[0].move !=  points[1].move)
			{
			 	switch (caseMove)
				{
				case 1:
				colisionPointFlag ^= 0x40;
				break;
				case 2:
				colisionPointFlag ^= 0x80;
				break;
				case 3:
				colisionPointFlag ^= 0xC0;
				break;
				default:
				break;
				}  
			}
	 	  }
	 }


	 if(points[0].y - points[1].y	== -1 || points[0].y - points[1].y ==1)
	 {
	 	if ( abs(pointsNext[1] - pointsNext[4])== 1)
		{
			if (points[0].move !=  points[1].move)
			{
			 	switch (caseMove)
				{
				case 1:
				colisionPointFlag ^= 0x40;
				break;
				case 2:
				colisionPointFlag ^= 0x80;
				break;
				case 3:
				colisionPointFlag ^= 0xC0;
				break;
				default:
				break;
				}  
			}
	 	  }
	 }



	 	 if(points[0].x - points[2].x	== -1 || points[0].x - points[2].x ==1)
	 {
	 	if ( abs( pointsNext[0]-pointsNext[6])== 1)
		{
			if (points[0].move !=  points[2].move)
			{
			 	switch (caseMove)
				{
				case 4:
				colisionPointFlag ^= 0x100;
				break;
				case 5:
				colisionPointFlag ^= 0x200;
				break;
				case 6:
				colisionPointFlag ^= 0x300;
				break;
				default:
				break;
				}  
			}
	 	  }
	 }


	 if(points[0].y - points[2].y	== -1 || points[0].y - points[2].y ==1)
	 {
	 	if ( abs(pointsNext[1] - pointsNext[7] == 1)
		{
			if (points[0].move !=  points[2].move)
			{

			 	if (points[0].move ==  points[2].move)
				{
				 	switch (caseMove)
					{
					case 4:
					colisionPointFlag ^= 0x100;
					break;
					case 5:
					colisionPointFlag ^= 0x200;
					break;
					case 6:
					colisionPointFlag ^= 0x300;
					break;
					default:
					break;
					}  
				}
			}
	 	  }
	 }


 	 if(points[1].x - points[2].x	== -1 || points[1].x - points[2].x ==1)
	 {
	 	if ( abs(pointsNext[3] - pointsNext[6]) == 1)
		{
			if (points[1].move !=  points[2].move)
			{
					switch (caseMove)
					{
					case 7:
					colisionPointFlag ^= 0x400;
					break;
					case 8:
					colisionPointFlag ^= 0x800;
					break;
					case 9:
					colisionPointFlag ^= 0xC00;
					break;
					default:
					break;
					}  

			}
	 	  }
	 }


	 if(points[1].y - points[2].y	== -1 || points[1].y - points[2].y ==1)
	 {
	 	if ( abs(pointsNext[4] - pointsNext[7]) == 1)
		{
			if (points[1].move !=  points[2].move)
			{
				switch (caseMove)
					{
					case 7:
					colisionPointFlag ^= 0x400;
					break;
					case 8:
					colisionPointFlag ^= 0x800;
					break;
					case 9:
					colisionPointFlag ^= 0xC00;
					break;
					default:
					break;
					}

			}
	 	  }
	 }


	   if (	colisionPointFlag >=0x40 && colisionPointFlag<=0xC00)
	   return colisionPointFlag ;
	   else
	   return 0;
}

 
int point2pointColisionNeighbours(void)							// point to point collision	 when they are symmetric and															 	
															// they are neighbours and there is no free cell between them	
//
{
	short i;

 


	//if (pointNext[2]==1 && pointNext[5]==1)
 
	 
	if(pointsNext[0] == points[1].x  && pointsNext[1]==points[1].y )		 // point1 to point2 collision
																			 //	  point1 New Position with present point2
	{
			switch (caseMove)
					{
					case 1:
					colisionPointFlag ^= 0x1000;
					break;
					case 2:
					colisionPointFlag ^= 0x2000;
					break;
					case 3:
					colisionPointFlag ^= 0x3000;
					break;
					default:
					break;
					}
		 
								 
	}
	if(points[0].x ==pointsNext[3]  && points[0].y==pointsNext[4])		  // point2 New Position with present point1

 	{
	 			switch (caseMove)
					{
					case 1:
					colisionPointFlag ^= 0x4000;
					break;
					case 2:
					colisionPointFlag ^= 0x8000;
					break;
					case 3:
					colisionPointFlag ^= 0xC000;
					break;
					default:
					break;
					}
							 
	}


	if(pointsNext[0] == points[2].x  && pointsNext[1]==points[2].y )		 // point1 to point3 collision
																			 //	  point1 New Position with present point2
	{
			switch (caseMove)
					{
					case 4:
					colisionPointFlag ^= 0x10000;
					break;
					case 5:
					colisionPointFlag ^= 0x20000;
					break;
					case 6:
					colisionPointFlag ^= 0x30000;
					break;
					default:
					break;
					}
								 
	}
	if(points[0].x ==pointsNext[6]  && points[0].y==pointsNext[7])		  // point3 New Position with present point1

	{
				switch (caseMove)
					{
					case 4:
					colisionPointFlag ^= 0x40000;
					break;
					case 5:
					colisionPointFlag ^= 0x80000;
					break;
					case 6:
					colisionPointFlag ^= 0xC0000;
					break;
					default:
					break;
					}
								 
	}


		if(pointsNext[3] == points[2].x  && pointsNext[4]==points[2].y )		 // point2 to point3 collision
																			 //	  point2 New Position with present point2
	{
			switch (caseMove)
					{
					case 7:
					colisionPointFlag ^= 0x100000;
					break;
					case 8:
					colisionPointFlag ^= 0x200000;
					break;
					case 9:
					colisionPointFlag ^= 0x300000;
					break;
					default:
					break;
					}
								 
	}
	if(points[1].x ==pointsNext[6]  && points[1].y==pointsNext[7])		  // point3 New Position with present point2

	{
			switch (caseMove)
					{
					case 7:
					colisionPointFlag ^= 0x400000;
					break;
					case 8:
					colisionPointFlag ^= 0x800000;
					break;
					case 9:
					colisionPointFlag ^= 0xC00000;
					break;
					default:
					break;
					}
								 
	}





	 
		if(colisionPointFlag>=0x1000 && colisionPointFlag<=0xC00000 )
			return colisionPointFlag;


	return 0;
}



int P3ColisionCase3Move (void)   // case 1 when three point are in conflict for free cell
{

	int case3Move;
	  
   if (pointsNext[2]==1 && pointsNext[5]==0 && pointsNext[8]==0)
   case3Move = 1;
   if (pointsNext[2]==1 && pointsNext[5]==1 && pointsNext[8]==0)
   case3Move = 2;
   if (pointsNext[2]==1 && pointsNext[5]==0 && pointsNext[8]==1)
  	case3Move= 3;
   if (pointsNext[2]==0 && pointsNext[5]==1 && pointsNext[8]==0)
  	case3Move= 4;
   if (pointsNext[2]==0 && pointsNext[5]==1 && pointsNext[8]==1)
   case3Move = 5;
   if (pointsNext[2]==0 && pointsNext[5]==0 && pointsNext[8]==1)
   case3Move = 6;
   if (pointsNext[2]==1 && pointsNext[5]==1 && pointsNext[8]==1)
   case3Move = 7;
 
  // case 1
	if (pointsNext[0] == pointsNext[3] && pointsNext[1]==pointsNext[4] && 
	pointsNext[0] == pointsNext[6] && pointsNext[1]==pointsNext[7] && 
	pointsNext[3] == pointsNext[6] && pointsNext[4]==pointsNext[7] )

	{
		switch(case3Move)		  //i 3trite tochki li se dvijat za  da ima koliziq 
									// ili e dostatychno da se dviji i edna za da ima koliziq
		{
		case 1:
		   P3Flag ^= 0x01;break;
		case 2:
		   P3Flag ^= 0x02;break;
		case 3:
		   P3Flag ^= 0x03;break;
		case 4:
		   P3Flag ^= 0x04;break;
		case 5:
		   P3Flag ^= 0x08;break;
		case 6:
		   P3Flag ^= 0x0C;break;
		case 7:		  
		   P3Flag ^= 0x10;break;
		default: break;
		}	   
	}

	if (P3Flag > 0 && P3Flag <= 0x10)
		return P3Flag ;
	else
		return 0;


}



	//monday - two points hit static point case 4
int  Corner(void)                   // ONE POINT HITS  ONE OF TWO POINTS WHO ARE IN CONFLICT
{
	if (pointsNext[0] == points[1].x && pointsNext[1]==points[1].y &&    //when point 1 and 3 hit point 2
	pointsNext[0] == pointsNext[6] && pointsNext[1]==pointsNext[7] )
	{
	

	}

	if (points[0].x == pointsNext[3] && points[0].y==pointsNext[4] && 	//when point 2 and 3 hit point 1 
	pointsNext[3] == pointsNext[6] && pointsNext[4]==pointsNext[7] )
	{
	
	}

	if (pointsNext[0] == pointsNext[3] && pointsNext[1]==pointsNext[4] &&   //when point 1 and 2 hits point 3
	pointsNext[0] == points[2].x && pointsNext[1]==points[2].y )
	{
	  
	}
	if (P3Flag>0x10  && P3Flag<=0x10)                            // UNRESOLVE FLAG MAX BOUND
	return P3Flag;
	else
	return 0;

}


	//tryin' to check for case 5
	// 1 i 2 se nacepvate diagonalno, 3 gi natrisa m/u pixelite
int CollisionPixelBound (void)
{
	if(pointsNext[0] == points[1].x  && pointsNext[1]==points[1].y )			 
		if(abs(points[0].x - points[2].x == 1) && abs(points[1].y - points[2].y) == 1 )
			  	if(abs(points[1].x - pointNext[6]) == 1 && abs(points[0].y - pointNext[7]) == 1 )
					  {


					  }


	if(pointsNext[3] == points[0].x  && pointsNext[4]==points[0].y )
		if(abs(points[0].x - points[2].x == 1) || abs(points[1].y - points[2].y) == 1 )
			  	if(abs(points[1].x - pointNext[6]) == 1 && abs(points[0].y - pointNext[7]) == 1 )
					  {



					  }

	 //razmenqme x i y
	 if(pointsNext[0] == points[1].x  && pointsNext[1]==points[1].y )			 
		if(abs(points[0].y - points[2].y) == 1 && abs(points[1].x - points[2].x)==1)
			  	if(abs(points[1].y - pointNext[7]) == 1 && abs(points[0].x - pointNext[6]) == 1)
					  {


					  }


	if(pointsNext[3] == points[0].x  && pointsNext[4]==points[0].y )
		if(abs(points[0].y - points[2].y) == 1 && abs(points[1].x - points[2].x)==1)
			  	if(abs(points[1].y - pointNext[7]) == 1 && abs(points[0].x - pointNext[6]) == 1)
					  {



					  }
	// 1 i 3 se nacepvat diagonalno, 2 gi nacepva m/u pixelite
	if(pointsNext[6] == points[0].x  && pointsNext[7]==points[0].y )			 
		if(abs(points[0].x - points[1].x == 1) && abs(points[2].y - points[1].y) == 1 )
			  	if(abs(points[0].x - pointNext[3]) == 1 && abs(points[2].y - pointNext[4]) == 1 )
					  {


					  }
	if(pointsNext[0] == points[2].x  && pointsNext[1]==points[2].y )			 
		if(abs(points[0].x - points[1].x == 1) && abs(points[2].y - points[1].y) == 1 )
			  	if(abs(points[0].x - pointNext[3]) == 1 && abs(points[2].y - pointNext[4]) == 1 )
					  {


					  }
	//obryshtame po x i y
	if(pointsNext[6] == points[0].x  && pointsNext[7]==points[0].y )			 
		if(abs(points[0].y - points[1].y == 1) && abs(points[2].x - points[1].x) == 1 )
			  	if(abs(points[0].y - pointNext[4]) == 1 && abs(points[2].x - pointNext[3]) == 1 )
					  {


					  }
	if(pointsNext[0] == points[2].x  && pointsNext[1]==points[2].y )			 
		if(abs(points[0].y - points[1].y == 1) && abs(points[2].x - points[1].x) == 1 )
			  	if(abs(points[0].y - pointNext[4]) == 1 && abs(points[2].x - pointNext[3]) == 1 )
					  {


					  }
	// 2 i 3 se nacepvat diagonalni, 1 gi udrq m/u pixelite
	if(pointsNext[6] == points[1].x  && pointsNext[7]==points[1].y )			 
		if(abs(points[1].x - points[0].x == 1) && abs(points[2].y - points[0].y) == 1 )
			  	if(abs(points[1].x - pointNext[0]) == 1 && abs(points[2].y - pointNext[1]) == 1 )
					  {


					  }
	if(pointsNext[3] == points[2].x  && pointsNext[4]==points[2].y )			 
		if(abs(points[1].x - points[0].x == 1) && abs(points[2].y - points[0].y) == 1 )
			  	if(abs(points[1].x - pointNext[0]) == 1 && abs(points[2].y - pointNext[1]) == 1 )
					  {


					  }
	//obryshtame x i y
	 if(pointsNext[6] == points[1].x  && pointsNext[7]==points[1].y )			 
		if(abs(points[1].x - points[0].x == 1) && abs(points[2].y - points[0].y) == 1 )
			  	if(abs(points[1].x - pointNext[0]) == 1 && abs(points[2].y - pointNext[1]) == 1 )
					  {


					  }
	if(pointsNext[3] == points[2].x  && pointsNext[4]==points[2].y )			 
		if(abs(points[1].y - points[0].y == 1) && abs(points[2].x - points[0].x) == 1 )
			  	if(abs(points[1].y - pointNext[1]) == 1 && abs(points[2].x - pointNext[0]) == 1 )
					  {


					  }
	 //end of case 5

				if ( P3Flag >   && <= P3Flag)             // UNUSED FLAG !!!
					return P3Flag
				else
				return 0;
}



int AllPointsInSame_FreeCell(void)  // all points in the same line or diagonal with free space between two of them
//checking for case 6
{	
	//1 i 2 edno s/u drugo, 3 natrisa otzade 1
	if(pointsNext[0]==pointsNext[3] && pointsNext[1]==pointsNext[4])
	   if(pointsNext[6]==points[0].x && pointsNext[7]==points[0].y)
	      if(points[0].move !=  points[1].move && points[0].move ==  points[2].move)
		  {

		  
		  
		  }
	 //1 i 2 edno s/u drugo, 3 natrisa otzade 2
	if(pointsNext[0]==pointsNext[3] && pointsNext[1]==pointsNext[4])
	   if(pointsNext[6]==points[1].x && pointsNext[7]==points[1].y)
	      if(points[0].move !=  points[1].move && points[1].move ==  points[2].move)
		  {

		  
		  
		  }


	//1 i 3 edno s/u drugo, 2 natrisa otzade 1
	if(pointsNext[0]==pointsNext[6] && pointsNext[1]==pointsNext[7])
	   if(pointsNext[3]==points[0].x && pointsNext[4]==points[0].y)
	      if(points[0].move !=  points[2].move && points[0].move ==  points[1].move)
		  {

		  
		  
		  }
   	//1 i 3 edno s/u drugo, 2 natrisa otzade 3
	if(pointsNext[0]==pointsNext[6] && pointsNext[1]==pointsNext[7])
	   if(pointsNext[3]==points[2].x && pointsNext[4]==points[2].y)
	      if(points[0].move !=  points[2].move && points[1].move ==  points[2].move)
		  {

		  
		  
		  }
   	//2 i 3 edno s/u drugo, 1 natrisa otzade 2
	if(pointsNext[3]==pointsNext[6] && pointsNext[4]==pointsNext[7])
	   if(pointsNext[0]==points[2].x && pointsNext[1]==points[1].y)
	      if(points[1].move !=  points[2].move && points[0].move ==  points[1].move)
		  {

		  
		  
		  }
	//2 i 3 edno s/u drugo, 1 natrisa otzade 3
	if(pointsNext[0]==pointsNext[6] && pointsNext[1]==pointsNext[7])
	   if(pointsNext[0]==points[2].x && pointsNext[1]==points[2].y)
	      if(points[1].move !=  points[2].move && points[0].move ==  points[2].move)
		  {

		  
		  
		  }
	//end of case 6

		  if (P3Flag > && P3Flag <=)        // UNUSED FLAG
			  return P3Flag;
		  else
			  return 0;

}

int AllPointsInSame(void)                                   // All points in  the same line or diagonal without free cell
{
	// all points in the same line or diagonal with free space between two of them
		  //case 7
	//1 i 2 edno s/u drugo, 3 natrisa otzade 1
	if(points[0].x==pointsNext[3] && points[0].y==pointsNext[4])
	   if(pointsNext[6]==points[0].x && pointsNext[7]==points[0].y)
	      if(points[0].move !=  points[1].move && points[0].move ==  points[2].move)
		  {

		  
		  
		  }
	 //1 i 2 edno s/u drugo, 3 natrisa otzade 2
	if(points[0].x==pointsNext[3] && points[0].y==pointsNext[4])
	   if(pointsNext[6]==points[1].x && pointsNext[7]==points[1].y)
	      if(points[0].move !=  points[1].move && points[1].move ==  points[2].move)
		  {

		  
		  
		  }


	//1 i 3 edno s/u drugo, 2 natrisa otzade 1
	if(points[0].x == pointsNext[6] && points[0].y == pointsNext[7])
	   if(pointsNext[3]==points[0].x && pointsNext[4]==points[0].y)
	      if(points[0].move !=  points[2].move && points[0].move ==  points[1].move)
		  {

		  
		  
		  }
   	//1 i 3 edno s/u drugo, 2 natrisa otzade 3
	if(points[0].x == pointsNext[6] && points[0].y == pointsNext[7])
	   if(pointsNext[3]==points[2].x && pointsNext[4]==points[2].y)
	      if(points[0].move !=  points[2].move && points[1].move ==  points[2].move)
		  {

		  
		  
		  }
   	//2 i 3 edno s/u drugo, 1 natrisa otzade 2
	if(points[1].x==pointsNext[6] && points[1].y==pointsNext[7])
	   if(pointsNext[0]==points[2].x && pointsNext[1]==points[1].y)
	      if(points[1].move !=  points[2].move && points[0].move ==  points[1].move)
		  {

		  
		  
		  }
	//2 i 3 edno s/u drugo, 1 natrisa otzade 3
	if(points[1].x==pointsNext[6] && points[1].y==pointsNext[7])
	   if(pointsNext[0]==points[2].x && pointsNext[1]==points[2].y)
	      if(points[1].move !=  points[2].move && points[0].move ==  points[2].move)
		  {

		  
		  
		  }
   //reversnato
   if(pointsNext[0]==points[1].x && pointsNext[1]==points[1].y)
	   if(pointsNext[6]==points[0].x && pointsNext[7]==points[0].y)
	      if(points[0].move !=  points[1].move && points[0].move ==  points[2].move)
		  {

		  
		  
		  }
	 //1 i 2 edno s/u drugo, 3 natrisa otzade 2
	if(pointsNext[0]==points[1].x && pointsNext[1]==points[1].y)
	   if(pointsNext[6]==points[1].x && pointsNext[7]==points[1].y)
	      if(points[0].move !=  points[1].move && points[1].move ==  points[2].move)
		  {

		  
		  
		  }


	//1 i 3 edno s/u drugo, 2 natrisa otzade 1
	if(pointsNext[0]==points[2].x && pointsNext[1]==points[2].y)
	   if(pointsNext[3]==points[0].x && pointsNext[4]==points[0].y)
	      if(points[0].move !=  points[2].move && points[0].move ==  points[1].move)
		  {

		  
		  
		  }
   	//1 i 3 edno s/u drugo, 2 natrisa otzade 3
	if(pointsNext[0]==points[2].x && pointsNext[1]==points[2].y)
	   if(pointsNext[3]==points[2].x && pointsNext[4]==points[2].y)
	      if(points[0].move !=  points[2].move && points[1].move ==  points[2].move)
		  {

		  
		  
		  }
   	//2 i 3 edno s/u drugo, 1 natrisa otzade 2
	if(pointsNext[3]==points[2].x && pointsNext[4]==points[2].y)
	   if(pointsNext[0]==points[2].x && pointsNext[1]==points[1].y)
	      if(points[1].move !=  points[2].move && points[0].move ==  points[1].move)
		  {

		  
		  
		  }
	//2 i 3 edno s/u drugo, 1 natrisa otzade 3
	if(pointsNext[3]==points[2].x && pointsNext[4]==points[2].y)
	   if(pointsNext[0]==points[2].x && pointsNext[1]==points[2].y)
	      if(points[1].move !=  points[2].move && points[0].move ==  points[2].move)
		  {

		  
		  
		  }
    //end of case 7
		  if (P3Flag > && P3Flag <=)        // UNUSED FLAG
			  return P3Flag;
		  else
			  return 0;

}

int  Corner_FreeCell (void)                   // ONE POINT HITS  ONE OF TWO POINTS WHO ARE IN CONFLICT IF FREE CELL

	//case 3
		if (pointsNext[0] == pointsNext[3] && pointsNext[1]== pointsNext[4] ) //when point 1 and 2 colision for free cell
			if(pointsNext[6] == points[0].x && pointsNext[7]==points[0].y)		  // when point 3 hit  point  1
				 
				{
			
			
				}

		if (pointsNext[0] == pointsNext[3] && pointsNext[1]== pointsNext[4] ) //when point 1 and 2 colision for free cell
			if(pointsNext[6] == points[1].x && pointsNext[7]==points[1].y)		  // when point 3 hit  point  2
			 
				{
			
			
				}

		if (pointsNext[0] == pointsNext[6] && pointsNext[1]== pointsNext[7] ) //when point 1 and 3 colision for free cell
			if(pointsNext[3] == points[0].x && pointsNext[4]==points[0].y)		  // when point 2 hit  point  1
				 
				{
			
			
				}

		if (pointsNext[0] == pointsNext[6] && pointsNext[1]== pointsNext[7] ) //when point 1 and 3 colision for free cell
			if(pointsNext[3] == points[2].x && pointsNext[4]==points[2].y)		  // when point 2 hit  point  3
			 
				{
			
			
				}

		if (pointsNext[3] == pointsNext[6] && pointsNext[4]== pointsNext[7] ) //when point 2 and 3 colision for free cell
			if(pointsNext[0] == points[1].x && pointsNext[1]==points[1].y)		  // when point 1 hit  point  2
				 
				{
			
			
				}

		if (pointsNext[3] == pointsNext[6] && pointsNext[4]== pointsNext[7] ) //when point 2 and 3 colision for free cell
			if(pointsNext[0] == points[2].x && pointsNext[1]==points[2].y)		  // when point 1 hit  point  3
			 
				{
			
			
				}

		// end of case 3
}

		// case 2
int  AnyPointHitsOtherWithDifferentDirection (void)
{
	if(points[0].move !=  points[1].move && points[1].move != points[2].move && points[0].move !=  points[2].move)
	{
	  
	  if (pointsNext[0] == points[1].x	&& pointsNext[1] == points[1].y)					 //1 i 2 po diagonal
		  if (pointsNext[3] == points[2].x	&& pointsNext[4] == points[2].y)				// point 2 hit point 3
				  {


				  }
																					 //1 i 3 po diagonal
	   if (pointsNext[0] == points[2].x	&& pointsNext[1] == points[2].y)			 // point 3 hit point 2
		   if (pointsNext[6] == points[1].x	&& pointsNext[7] == points[1].y)
				  {


				  }
 																				   
	   if (pointsNext[6] == points[1].x	&& pointsNext[7] == points[1].y)		  //2 i 3 po diagonal
		   if (pointsNext[3] == points[0].x	&& pointsNext[4] == points[0].y)	  // point 2 hit point 1
				  {


				  }



 	    if (pointsNext[3] == points[0].x	&& pointsNext[4] == points[0].y)		//1 i 2 po diagonal
		  if (pointsNext[0] == points[2].x	&& pointsNext[1] == points[2].y)		// point 1 hit point 3
				  {


				  }
																					 //1 i 3 po diagonal
	   if (pointsNext[6] == points[0].x	&& pointsNext[7] == points[0].y)			 // point 1 hit point 2
		   if (pointsNext[0] == points[1].x	&& pointsNext[1] == points[1].y)
				  {


				  }
 																				   
	   if (pointsNext[3] == points[2].x	&& pointsNext[4] == points[2].y)		  //2 i 3 po diagonal
		   if (pointsNext[6] == points[0].x	&& pointsNext[7] == points[0].y)	  // point 3 hits point 1
				  {


				  }



	  }

	if (P3Flag >  && P3Flag <)                       // UNUSED FLAG
		return P3Flag;
	else
		return 0;
}
	  //end of case 2


	// case 8

int TwoPointsHitThirdByDiagonal(void)
{
	if (pointsNext[0] == points[2].x && pointsNext[1] == points[2].y)   //point 1 and point 2 hits point 3
		if (pointsNext[3] == points[2].x && pointsNext[4] == points[2].y)
			if ( abs(points[0].x - points[1].x) == 2 && abs(points[0].y - points[1].y) == 2 )
			{

			}

	if (pointsNext[0] == points[1].x && pointsNext[1] == points[1].y)   //point 1 and point 3 hits point 2
		if (pointsNext[6] == points[1].x && pointsNext[7] == points[1].y)
			if ( abs(points[0].x - points[2].x) == 2 && abs(points[0].y - points[2].y) == 2 )
			{

			}

	if (pointsNext[3] == points[0].x && pointsNext[4] == points[0].y)   //point 2 and point 3 hits point 1
		if (pointsNext[6] == points[0].x && pointsNext[7] == points[0].y)
			if ( abs(points[1].x - points[2].x) == 2 && abs(points[1].y - points[2].y) == 2 )
			{

			}

			if (P3Flag >   && P3Flag <=)      // UNUSED  FLAG !!!!
				return P3Flag;
			else
				return 0;
}
	

void simulation (void)
{


}

void point2ColisionSolveSymetric(void)		   // colllision solve for SYMETRIC FREE CELL AND  SYMETRIC  NEIGHBORS
										// FOR SYMETRIC FREE CELL USE SIMULATION
										 // have to use simulation 
{
 int a, b;

	if (colisionPointFlag&0x03 !=0 )
	{  a=0;
	   b=1;
	
	}														
	
	if(colisionPointFlag& 0x0C !=0)
	{
		a=0;
		b=2;
 
	}

	if(colisionPointFlag& 0x30 !=0 )
	{
		a=1;
		b=2;
	 
	}


	if (colisionPointFlag&0xC0 !=0 )
	{  a=0;
	   b=1;
	
	}														
	
	if(colisionPointFlag& 0x300 !=0)
	{
		a=0;
		b=2;
 
	}

	if(colisionPointFlag& 0xC00 !=0 )
	{
		a=1;
		b=2;
	 
	}

// kratyk variant
/*
		points[a].move - > aplToX *= 	-1;
		points[a].move - > aplToY *= 	-1;
		if ( points[a].move - > aplToX  = = points[b].move - > aplToX  &&
			 points[a].move - > aplToY  = = points[b].move - > aplToY )  
			 pointRevertLaw(&points[a]);
			 pointRevertLaw(&points[b]);
*/

	
	 
	   if (points[a].move== moveLaws[1] && points[b].move== moveLaws[0] )
	   {
	   pointRevertLaw(&points[a]);
	   pointRevertLaw(&points[b]);
	   }

	   if (points[a].move== moveLaws[0] && points[b].move== moveLaws[1] )
	   {
	   pointRevertLaw(&points[a]);
	   pointRevertLaw(&points[b]);
	   }


	    if (points[a].move== moveLaws[2] && points[b].move== moveLaws[3] )
	   {
	   pointRevertLaw(&points[a]);
	   pointRevertLaw(&points[b]);
	   }

	   if (points[a].move== moveLaws[3] && points[b].move== moveLaws[2] )
	   {
	   pointRevertLaw(&points[a]);
	   pointRevertLaw(&points[b]);
	   }


	     if (points[a].move== moveLaws[4] && points[b].move== moveLaws[5] )
	   {
	   pointRevertLaw(&points[a]);
	   pointRevertLaw(&points[b]);
	   }

	   if (points[a].move== moveLaws[5] && points[b].move== moveLaws[4] )
	   {
	   pointRevertLaw(&points[a]);
	   pointRevertLaw(&points[b]);
	   }


	    if (points[a].move== moveLaws[6] && points[b].move== moveLaws[7] )
	   {
	   pointRevertLaw(&points[a]);
	   pointRevertLaw(&points[b]);
	   }

	   if (points[a].move== moveLaws[7] && points[b].move== moveLaws[6] )
	   {
	   pointRevertLaw(&points[a]);
	   pointRevertLaw(&points[b]);
	   }

 	

}

void point2ColisionAsymetric(void)
{
	short speed1, speed2, a, b;

	
	if (point2pointColisionNeighbours())                                  // point 1 hits point 2
	{
		points[a].move - > aplToX *= 	-1;
		points[a].move - > aplToY *= 	-1;
		if ( points[a].move - > aplToX  ! = points[b].move - > aplToX  ||
			 points[a].move - > aplToY  ! = points[b].move - > aplToY )                  // ??? MOJE LI DA SE UMNOJAVAT ELEMENTI NA STRUKTURA PO TOZI NACHIN
			if ( abs (points[a].x - points[b].x)== 1   && abs (points[a].y - points[b].y)== 1 )        // udrq po diagonal
		{
		pointRevertLaw(&points[a]);
	    pointRevertLaw(&points[b]);
		speed1= points[a]/2;
		points[a].speed = speed1
		if (speed1==0)
			speed1=1;
		points[b].speed += speed1;

		}
			else
		if (abs (points[a].x - points[b].x)== 0   ||  abs (points[a].y - points[b].y)== 0 )            // udrq vertiakalno
		{																							  //  NEQSEN SLUCHAI ???????
		
		speed1= points[a]/2;
		speed2= points[b]/2;
		
		points[a].speed = speed1 ;
		points[b].speed = speed1 + speed2;
	

		}
	}

}

// for three point 3

void revert3 (void)
{
	 	 pointRevertLaw(&points[0]);
		 pointRevertLaw(&points[1]);
	     pointRevertLaw(&points[2]);
}

void SolveUsingRevert (void)
{
	if (P3ColisionCase3Move())               // using simulation
		revert3();
	if (CollisionPixelBound ())
		revert3();
	if (TwoPointsHitThirdByDiagonal())
		revert3();

}
															// without free cell conflict
void SolveOneLineCollision (void)                        // a point and c point are end points,  point b is midlle point

{

	short a,b,c;
	if ( AllPointsInSame() )                                   // 
		pointRevertLaw(&points[a]);
	    pointRevertLaw(&points[c]);
		if (maxSpeed() == points[c].speed && points[a].move == points[b].move)
			pointRevertLaw(&points[b]);
		else
			if (maxSpeed() == points[a].speed && points[b].move == points[c].move)
			pointRevertLaw(&points[b]); 



}

															   
void SolveOneLineCollision (void)                    // a point and c point are end points,  point b is midlle point; with  free cell conflict

{

	short a,b,c;
	if ( AllPointsInSame_FreeCell() )                //  if ( point a and  point b ) are in conflict, using simulation (a,b)  b revert if c max ??
//		pointRevertLaw(&points[a]);
	    pointRevertLaw(&points[c]);
		simulation ();

}


void CornerSolve()
{
	short a,b,c;                                // ( point a and point b ) are in conflict , point c hits a 
	if (Corner())
	{
		if (maxSpeed() = points[c].speed)
		{
			points[c].move =   pointRevertLaw(&points[a]);
			points[a].move =  points[c].move;
		}
		else 
		revert3();
	}
}

 


void CornerSolve_FreeCell()
{												// using simulation
	short a,b,c;                                // ( point a and point b ) are in conflict , point c hits a 
	if (Corner_FreeCell())
	{
		if (maxSpeed() = points[c].speed)
		{
			points[c].move =   pointRevertLaw(&points[a]);
			points[a].move =  points[c].move;
		}
		else 
		revert3();
	}
}

// CASE  when all points have different direction  UNRESOLVED ???









